<template>
    <div class="mainBox">
        <span style="font-size: 16px;font-weight: 500px;">我的购物车</span>
        <span style="font-size: 12px;">共0门订单</span>
        <table>
            <thead :style="{ borderBottom: '1px solid #E9E9E9' }">
                <th><a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange">
                    全选
                </a-checkbox></th>
                <th>课程名称</th>
                <th>原价</th>
                <th>优惠</th>
                <th>操作</th>
            </thead>
            <tbody>
                <tr v-for="(item, index) in shopList" :key="index">
                    <td><a-checkbox v-model="item.checked" @change="onChange">
                        <img :src="item.course.coverFileUrl" alt="">
                    </a-checkbox></td>
                    <td>{{ item.course.courseSubtitle }}</td>
                    <td>
                        <div v-if="item.course.isDiscount == 0">
                            <span class="red">￥{{ item.course.coursePrice }}</span>
                        </div>
                        <div v-else>
                            <span class="red">￥{{ item.course.discountPrice }}</span>
                            <span class="old-price"> {{ item.course.coursePrice }}</span>
                        </div>
                    </td>
                    <td>
                        <span  class="desc" v-if="item.course.discountDesc">{{ item.course.discountDesc }}</span>
                        <span class="price" v-else>原价</span>
                    </td>
                    <td>
                        <a-button type="primary">
                            删除
                        </a-button>
                    </td>
                </tr>
             </tbody>
             <thead :style="{ borderBottom: '1px solid #E9E9E9' }" style="position: relative;">
                <th><a-checkbox :indeterminate="indeterminate" :checked="checkAll" @change="onCheckAllChange">
                    全选
                </a-checkbox></th>
                <th style="position: absolute;right: 200px;width: 100px;">合计：￥</th>
                <th style="position: absolute;right: 0;width: 199px;height: 51px;padding: 0;">
                    <button style="width:199px;height: 51px;background-color: #999;">提交</button>
                </th>
            </thead>
        </table>
    </div>
</template>
<script>
import { getShop } from '@/api/request';
export default {
  data() {
    return {
      indeterminate: false,
      checkAll: false,
      shopList: [], // 购物车列表数据
    };
  },
  methods: {
    onChange() {
        const checkedCount = this.shopList.filter(item => item.checked).length;
        this.indeterminate = checkedCount > 0 && checkedCount < this.shopList.length;
        this.checkAll = checkedCount === this.shopList.length;
    },
    onCheckAllChange(e) {
        this.shopList.forEach(item => {
            item.checked = e.target.checked;
        });
        this.indeterminate = false;
        this.checkAll = e.target.checked;
    },
  },
  created() {
    getShop().then(res => {
      console.log(666676);
      console.log(res.shoppingCartList);
      this.shopList = res.shoppingCartList;
      
    });
  }
};
</script>
<style lang="scss" scoped>
.mainBox {
    width: 1160px;
    margin: 0 auto;
    height: 100%;
    margin-top: 20px;
    >span {
        margin-top: 10px;
        margin-right: 20px;
    }
}
img {
    width: 156px;
    height: 104px;
}
table {
    margin: 0 auto;
    margin-top: 20px;
    margin-bottom: 50px;
    border-collapse: collapse; /* 合并边框 */
    width: 100%; /* 表格宽度 */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* 添加阴影 */
}
th {
    background-color: #ddd; /* 设置表头背景颜色 */
    // width: 20%;
    &:first-child {
        width: 20%; 
    }
    &:nth-child(2){
        width: 35%;
    }
}
th, td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #ddd; /* 添加底部边框 */
}
tr:hover {
    background-color: #f5f5f5; /* 鼠标悬停时的背景颜色 */
}
.red {
    color: #ff4500;
    font-weight: 500;
}
.old-price {
    color: #999!important;
    text-decoration: line-through;
    font-size: 12px;
    margin-left: 5px;
}
.desc {
    color: #fa8c16!important;
    background: #fff7e6;
    border: 1px solid #d9d9d9;
    border-color: #ffd591;
    padding: 0 7px;
    margin-right: 8px;
    font-size: 16px;
    line-height: 20px;
}
.price {
    color: blue;
    background-color: rgba(16, 143, 233, 0.375);;
    border: 1px solid #1588f3;
    padding: 0 7px;
    margin-right: 8px;
    font-size: 16px;
    line-height: 20px;
}
</style>